package com.wenhao.utils;

import java.util.concurrent.CountDownLatch;

/**
 * 减法计数器
 *
 * @author Wenhao Tong
 * @create 2021-08-20 11:39
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        // 计数器总数是6
        CountDownLatch countDownLatch = new CountDownLatch(6);
        // 计数器减一
//        countDownLatch.countDown();

        for (int i = 0;i < 6;i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " go out...");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        // 计数器清零之后才会继续执行
        countDownLatch.await();
        System.out.println("close door");
    }
}
